from django.shortcuts import HttpResponse
import cmdb.api.http_result as hh
from cmdb import models
import uuid
from cmdb.util import time
from django.conf import settings
import json
from cmdb.util import http_util as hu
from cmdb.api.session import session_set
from cmdb.api.session import session_get
from cmdb.api.session import session_clear
from cmdb.util import file_utils

def file_md5(req):
    hd = hu.json_obj(req)
    data = hd[0]
    if data:
        name = data.get('file_name', None)
        mm = file_utils.file_md5(name)
        print(name, mm)
        if 'No such file or directory' in mm:
            return hh.resp_result(0, mm)
        else:
            return hh.resp_result(1, hh.RESULT_SUCCESS, {'file_md5': mm})
    else:
        return hh.resp_result(0, hh.RESULT_FAIL, {'error_info': hd[1]})





